Page({
  data: {
    showModalStatus: false,
    hasEmptyGrid: false,
    lat: [],
    index: 0,
    edu: '',
    book_time: '',
    book_date: '2017-9',
    is_score: '',
    picker_arr: [],
    picker_index: 0,
    tpl: '',
    oid: '',
    tt: '',
    _num: 0,
    _td: '',
    bbg: false

  },
  powerDrawer: function (e) {
    var currentStatu = e.currentTarget.dataset.statu;
    this.util(currentStatu);
  },
  util: function (currentStatu) {
    /* 动画部分 */
    // 第1步：创建动画实例 
    var animation = wx.createAnimation({
      duration: 200, //动画时长 
      timingFunction: "linear", //线性 
      delay: 0 //0则不延迟 
    });

    // 第2步：这个动画实例赋给当前的动画实例 
    this.animation = animation;

    // 第3步：执行第一组动画 
    animation.rotateY(100+"%").step();

    // 第4步：导出动画对象赋给数据对象储存 
    this.setData({
      animationData: animation.export()
    })

    // 第5步：设置定时器到指定时候后，执行第二组动画 
    setTimeout(function () {
      // 执行第二组动画 
      animation.rotateY(0).step();
      // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象 
      this.setData({
        animationData: animation
      })

      //关闭 
      if (currentStatu == "close") {
        this.setData(
          {
            showModalStatus: false
          }
        );
      }
    }.bind(this), 200)

    // 显示 
    if (currentStatu == "open") {
      this.setData(
        {
          showModalStatus: true
        }
      );
    }
  },
  // onLoad(options) {
  //     const date = new Date();
  //     const cur_year = date.getFullYear();
  //     const cur_month = date.getMonth() + 1;
  //     const weeks_ch = ['日', '一', '二', '三', '四', '五', '六'];
  //     this.calculateEmptyGrids(cur_year, cur_month);
  //     this.calculateDays(cur_year, cur_month);

  //     this.setData({
  //         cur_year,
  //         cur_month,
  //         weeks_ch,
  //         options: options,
  //     });
  //     // console.log(date)
  // },
  
  onLoad: function (options) {
    var that = this;
    const weeks_ch = ['日', '一', '二', '三', '四', '五', '六'];
    that.setData({
      options: options,
      weeks_ch,
    })
  },
  bindPickerChange: function (e) {
    // console.log('this.data.book_date')
    // console.log(this.data.book_date)
    var app = getApp()
    var that = this;
    this.setData({
      picker_index: e.detail.value,
      // book_date: e.currentTarget.dataset.date,
      sym: e.detail.value
    })
    //console.log(that.data.ym[e.detail.value].name)
    wx.request({
      url: app.globalData.host + '&g=App&m=Worker&a=nm',
      data: {
        id: that.data.options.id,
        sym: that.data.ym[e.detail.value].name
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        var ad = res.data.ad;
        that.setData({
          nw: res.data.nw,
        })
      }
    })
    // console.log('this.data.book_date')
    // console.log(this.data.book_date)
  },
  btnedu: function (e) {
    this.setData({
      edu: e.currentTarget.dataset.edu,
      // class: "subhover",
      _num: e.currentTarget.dataset.num
    })
    // console.log(this.data.edu)
  },
  bbt: function (e) {
    // console.log(e.currentTarget.dataset)
    this.setData({
      // book_time: e.currentTarget.dataset.dd,
      book_time: e.currentTarget.dataset.ymd,
      _td: e.currentTarget.dataset.dd,
      bbg: e.currentTarget.dataset.index,
    })

  },
  onShow: function () {
    var app = getApp()
    var that = this;
    var uid = wx.getStorageSync('uid');
    var picker_arr = []
    wx.request({
      url: app.globalData.host + '&g=App&m=Worker&a=info',
      data: { id: that.data.options.id, uid: uid, book_date: that.data.book_date},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        var ad = res.data.ad;
        var ym = res.data.ym;
        var lat = res.data.ad.lat;
        var lng = res.data.ad.lng;
        // console.log(that.data)
        // 年月选择
        ym.forEach(function (e) {
          picker_arr.push(e.name);
        })
        that.setData({
          tag: res.data.tag,
          evaluate: res.data.evaluate,
          cs: res.data.cs_point,
          ad: res.data.ad,
          tm: res.data.tm,
          ym: res.data.ym,
          lat: res.data.ad.lat,
          lng: res.data.ad.lng,
          picker_arr: picker_arr,
          book_time: that.data.book_time,
          book_date: that.data.book_date,
          // 地图标记
          markes: [{
            iconPath: "",
            id: 0,
            latitude: lat,
            longitude: lng,
            width: 33,
            height: 42
          }],
        })
      }
    }),
      // 日历
      wx.request({
        url: app.globalData.host + '&g=App&m=Worker&a=nm',
        data: {
          uid: uid,
          id: that.data.options.id,
          type: 2,
          is_score: 0,
          edu: that.data.edu,
          book_time: that.data.book_time,
          book_date: that.data.book_date,
          amount: '',
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res.data)
          var ad = res.data.ad;
          that.setData({
            nw: res.data.nw,
          })
        }
      })
    that.setData({
      isHide: 1,
    })
  },
  // 电话
  bindPhoneCall: function (e) {
    this.setData({
      tpl: e.currentTarget.dataset.tpl
    })
    // console.log(e.currentTarget.dataset.tpl)
    wx.makePhoneCall({
      phoneNumber: this.data.tpl,  //电话号码
    })
  },

  // getThisMonthDays(year, month) {
  //     return new Date(year, month, 0).getDate();
  // },
  // getFirstDayOfWeek(year, month) {
  //     return new Date(Date.UTC(year, month - 1, 1)).getDay();
  // },
  // calculateEmptyGrids(year, month) {
  //     const firstDayOfWeek = this.getFirstDayOfWeek(year, month);
  //     let empytGrids = [];
  //     if (firstDayOfWeek > 0) {
  //         for (let i = 0; i < firstDayOfWeek; i++) {
  //             empytGrids.push(i);
  //         }
  //         this.setData({
  //             hasEmptyGrid: true,
  //             empytGrids
  //         });
  //     } else {
  //         this.setData({
  //             hasEmptyGrid: false,
  //             empytGrids: []
  //         });
  //     }
  // },
  // calculateDays(year, month) {
  //     let days = [];
  //     const thisMonthDays = this.getThisMonthDays(year, month);
  //     for (let i = 1; i <= thisMonthDays; i++) {
  //         days.push(i);
  //     }
  //     this.setData({
  //         days
  //     });
  // },
  // handleCalendar(e) {
  //     const handle = e.currentTarget.dataset.handle;
  //     const cur_year = this.data.cur_year;
  //     const cur_month = this.data.cur_month;
  //     if (handle === 'prev') {
  //         let newMonth = cur_month - 1;
  //         let newYear = cur_year;
  //         if (newMonth < 1) {
  //             newYear = cur_year - 1;
  //             newMonth = 12;
  //         }

  //         this.calculateDays(newYear, newMonth);
  //         this.calculateEmptyGrids(newYear, newMonth);

  //         this.setData({
  //             cur_year: newYear,
  //             cur_month: newMonth
  //         })

  //     } else {
  //         let newMonth = cur_month + 1;
  //         let newYear = cur_year;
  //         if (newMonth > 12) {
  //             newYear = cur_year + 1;
  //             newMonth = 1;
  //         }

  //         this.calculateDays(newYear, newMonth);
  //         this.calculateEmptyGrids(newYear, newMonth);

  //         this.setData({
  //             cur_year: newYear,
  //             cur_month: newMonth
  //         })
  //     }
  // },
  // 设为收藏
  collect: function (e) {
    const that = this;
    var app = getApp()
    var uid = wx.getStorageSync('uid');
    wx.request({
      url: app.globalData.host + '&g=App&m=Worker&a=setwid',
      data: {
        uid: uid,
        id: that.data.options.id,
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        // console.log(res.data)
        wx.showModal({
          title: '提示',
          content: '设置成功',
          showCancel: false
        })
        that.setData({
        })
      }
    })
  },
  choseTime: function (e) {
    this.setData({
      tt: e.currentTarget.dataset.t,
    })
  },
  // 弹窗确定跳确定预约界面
  orderShow: function (e) {

    const that = this;
    var app = getApp()
    var uid = wx.getStorageSync('uid');
    if (that.data.tt == '' || that.data.edu == '' || that.data.book_time == '') {
      wx.showModal({
        title: '提示',
        content: '请选择科目与预约日期时间段',
        showCancel: false
      })
      return false
    }
    console.log(uid)
    console.log(that.data.options.id)
    console.log(that.data.tt)
    console.log(that.data.edu)
    console.log(that.data.book_time)
   // return false
    wx.request({
      url: app.globalData.host + '&g=App&m=Order&a=neworder',
      data: {
        uid: uid,
        id: that.data.options.id,
        type: 2,
        is_score: 0,
        edu: that.data.edu,
        book_time: that.data.tt,
        book_date: that.data.book_time,
        // oid: that.data.oid,
        // id:that.data.oid
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.status == 1) {
          var oid = res.data.oid
          data: {
            oid: res.data.oid
            // book_time: that.data.book_time;
            // book_date: that.data.book_date;
          }
          console.log(res.data.oid)
          wx.navigateTo({
            url: '/page/coach/order?id=' + oid
          })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.info,
            showCancel: false
          })
          return false

        }
      }

    })

    that.setData({
      isHide: 1,
    })
  },
  // 分享
  // onShareAppMessage: function (res) {
  //   var uid = wx.getStorageSync('uid');
  //   var that = this;
  //   var app = getApp()
  //   var scene = that.data.scene
  //   console.log(that.data.scene)
  //   console.log("1")
  //   return {
  //     title: '兴祥安驾校',
  //     path: '/page/coach/coach?scene=scene',
  //     success: function (res) {
  //       wx.request({
  //         url: app.globalData.host + '&g=App&m=Index&a=feedback',
  //         data: {
  //           scene: scene
  //         },
  //         header: {
  //           'content-type': 'application/json'
  //         },
  //       })
  //     },
  //     fail: function (res) {
  //     }
  //   }
  // }
})